function addSliceImage3p0
% addSliceImage3p0    add an image of a slice (or whatever) to axes
%
%
% to do: need to delete the previous images and markers (if any),
% rather than add them to the axes
%
% gs feb 2005
% gs april 2005 -- modified for mapAnalysis3p0
% gs may 2006 - modified for ephus compatibility
% ---------------------------------------------------------------

% retrieve the figure's data
try
    handles = get(gcf, 'UserData');
catch
end

% specify the default directory
d = handles.data.map.mapActive.directory;
% inds = strfind(d, '\');
% lastchar = inds(length(inds)-1);
% imgDir = [d(1:(lastchar)) 'images'];
% cd(imgDir);
inds = strfind(d, '\');
try
    lastchar = inds(length(inds) - 2); % 'standard' auto-generated filing system, old way
    imgDir = [d( 1 : lastchar ) 'images'];
    cd(imgDir);
catch
    try
        lastchar = inds(length(inds) - 1); % 'standard' auto-generated filing system, new way
        imgDir = [d( 1 : lastchar ) 'images'];
        cd(imgDir);
    catch
    end
end

% interactively select the file to open
[name, path] = uigetfile('*.*', 'Select an image file.');
if isnumeric(name)
    return
end
fullname = [path name];

% read in the image file & convert to RGB format
I = imread(fullname);
% R = ind2rgb(I, gray(256));
R = I; % GS20060524

% try
% delete the previous stuff
delete(handles.data.fig.traceBrowser.hSliceImg);

% display image
handles.data.fig.traceBrowser.hSliceImg = imagesc(flipud(R)); % GS20060524
daspect([1 1 1]);
% set(himg, 'ButtonDownFcn', 'addSliceImage');
set(gca, 'ButtonDownFcn', 'addSliceImage3p0');
title('Click to upload an image');

% distance scaling
try
    xrange = handles.data.acq.imageXrange;
    yrange = handles.data.acq.imageYrange;
catch
    xrange = 1900; % default param's from Ingrid's rig
    yrange = 1520;
end
set(handles.data.fig.traceBrowser.hSliceImg, ...
    'XData', [-xrange/2 xrange/2], 'YData', [-yrange/2 yrange/2]);
axis tight;

handleList = [handles.data.fig.traceBrowser.haxSliceImg_currentTrace; ...
        handles.data.fig.traceBrowser.hRectMapArea; handles.data.fig.traceBrowser.hBlankMap; ...
        handles.data.fig.traceBrowser.hSliceImg];
set(handles.data.fig.traceBrowser.haxSliceImg, 'Children', handleList); 
%     'yo1'
% catch
%     % display image
%     hSliceImg = imagesc(R);
%     daspect([1 1 1]);
%     % set(himg, 'ButtonDownFcn', 'addSliceImage');
%     set(gca, 'ButtonDownFcn', 'addSliceImage3p0');
%     title('Click to upload an image');
%     
%     % distance scaling
%     try
%         xrange = handles.data.acq.imageXrange;
%         yrange = handles.data.acq.imageYrange;
%     catch
%         xrange = 1900; % default param's from Ingrid's rig
%         yrange = 1520;
%     end
%     set(hSliceImg, ...
%         'XData', [-xrange/2 xrange/2], 'YData', [-yrange/2 yrange/2]);
%     axis tight;
%     'yo2'
% end

% % blank map array
% hold on;
% himgBlank = imagesc(zeros(16,16));
% set(himgBlank, 'AlphaData', .1, 'XData', [-data.map.magFacX data.map.magFacX], ...
%     'YData', [-data.map.magFacY data.map.magFacY]);
% set(data.handles.haxSliceImg, 'Position', [0.4919    0.7054    0.2840    0.2555], ...
%     'ButtonDownFcn', 'addSliceImage');
% daspect([1 1 1]);
% axis tight;
% pixTrace(himgBlank);

% % rectangle to mark mapping region
% hrect = rectangle;
% xdata = get(data.handles.himgP1, 'XData');
% ydata = get(data.handles.himgP1, 'YData');
% set(hrect, 'Position', [xdata(1) ydata(1) xdata(2)-xdata(1) ydata(2)-ydata(1)], ...
%     'EdgeColor', 'y', 'LineStyle', ':');

set(gcf, 'UserData', handles);